package com.example.test_activity.MVP.presenter;

import com.example.test_activity.MVP.view.IView;
import com.example.test_activity.http.HttpUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 旭 on 2017/5/5/005.
 */

public class ViewPresenter implements IViewPresenter {


    private IView view;

    public ViewPresenter(IView view)
    {
        this.view = view;
    }

    @Override
    public void reviseString(String string) {
        String user_name = string.substring(11,16);
        String user_number = string.substring(0,10);
        if (user_name.charAt(4) == ')')
        {
            user_name = user_name.substring(0,4);
        }
        if (user_name.charAt(3) == ')')
        {
            user_name = user_name.substring(0,3);
        }
        if (user_name.charAt(2) == ')')
        {
            user_name = user_name.substring(0,2);
        }

        List<String> list = new ArrayList<>();
        list.add(user_name);
        list.add(user_number);

        view.setName(list);
    }

    @Override
    public void doMethod(String method) {
        HttpUtil.getInstance().RestHttpUtil();
        if (method.equals("exit"))
        {
            view.exit();
        }else if (method.equals("logout"))
        {
            view.logout();
        }
    }
}
